package tech.aistar.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import tech.aistar.dto.Result;
import tech.aistar.entity.Urand;
import tech.aistar.service.impl.LevelServiceImpl;
import tech.aistar.service.impl.UrankServiceImpl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

@Controller
@RequestMapping("/rank")
public class UrankAction {
    @Autowired
    private UrankServiceImpl urankService;
    @Autowired
    private LevelServiceImpl levelService;
    @RequestMapping("/load")
    public String load(HttpSession session){
        //System.out.println(urankService.findScore());
        List<Urand> list= urankService.findScore();
        list.sort(new Comparator<Urand>() {
            @Override
            public int compare(Urand t1, Urand t2) {
                return t2.getRankScore().compareTo(t1.getRankScore());
            }
        });
        session.setAttribute("java",list);

       List<Urand> list1 = urankService.findScore1();
       list1.sort(new Comparator<Urand>() {
           @Override
           public int compare(Urand t1, Urand t2) {
               return t2.getRankScore().compareTo(t2.getRankScore());
           }
       });
       session.setAttribute("python",list1);

       List<Urand> list2 = urankService.findScore2();
       list2.sort(new Comparator<Urand>() {
           @Override
           public int compare(Urand t1, Urand t2) {
               return t2.getRankScore().compareTo(t1.getRankScore());
           }
       });
       session.setAttribute("c",list2);


       List<Urand> list3 = urankService.findScore3();
       list3.sort(new Comparator<Urand>() {
           @Override
           public int compare(Urand t1, Urand t2) {
               return t2.getRankScore().compareTo(t1.getRankScore());
           }
       });
       session.setAttribute("web",list3);

       List<Urand> list4 = urankService.findScore4();
       list4.sort(new Comparator<Urand>() {
           @Override
           public int compare(Urand t1, Urand t2) {
               return t2.getRankScore().compareTo(t1.getRankScore());
           }
       });
       session.setAttribute("sql",list4);
       return "rank";
    }

//    @PostMapping("/Rank")
//    public @ResponseBody Result rank(HttpServletRequest request, HttpSession session){
//
//
//
//
//
//
//
//        return new Result("700","111");
//    }
}
